package com.ss.android.article.base.feature.feed;

import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.StateListDrawable;
import android.os.Build;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bytedance.article.b.a.GsonDependManager;
import com.bytedance.common.utility.Logger;
import com.bytedance.common.utility.UIUtils;
import com.ss.android.article.base.app.AppData;

import java.io.Serializable;

public class FeedCellStyleConfig {
    public class FeedCellConfigModel implements Serializable {
        String[] cell_background_color;
        String[] color;
        int[] font_size;

        public FeedCellConfigModel() {

        }
    }

    private static final String TAG;
    private static FeedCellConfigModel mFeedCellConfigModel;
    private static int[] font_size;
    private static int[] color;
    private static int[] cell_background_color;
    private static String mListUiOption;

    static {
        int v7 = 4;
        int v6 = 3;
        int v5 = 2;
        TAG = FeedCellStyleConfig.class.getSimpleName();
        FeedCellStyleConfig.mListUiOption = AppData.getInstance().mListUiOption;
        Logger.d(FeedCellStyleConfig.TAG, FeedCellStyleConfig.mListUiOption);
        if (!android.support.design.a.isTextEmpty(FeedCellStyleConfig.mListUiOption)) {
            Object v0 = GsonDependManager.getInstance().fromJson(FeedCellStyleConfig.mListUiOption, FeedCellConfigModel.class);
            FeedCellStyleConfig.mFeedCellConfigModel = ((FeedCellConfigModel) v0);
            if (v0 != null) {


                if (FeedCellStyleConfig.mFeedCellConfigModel != null && FeedCellStyleConfig.mFeedCellConfigModel.font_size != null && FeedCellStyleConfig.mFeedCellConfigModel.font_size.length == v7) {
                    int[] v0_1 = new int[v7];
                    v0_1[0] = FeedCellStyleConfig.mFeedCellConfigModel.font_size[1];
                    v0_1[1] = FeedCellStyleConfig.mFeedCellConfigModel.font_size[0];
                    v0_1[v5] = FeedCellStyleConfig.mFeedCellConfigModel.font_size[v5];
                    v0_1[v6] = FeedCellStyleConfig.mFeedCellConfigModel.font_size[v6];
                    FeedCellStyleConfig.font_size = v0_1;
                }

                if (FeedCellStyleConfig.mFeedCellConfigModel != null
                        && FeedCellStyleConfig.mFeedCellConfigModel.color != null
                        && FeedCellStyleConfig.mFeedCellConfigModel.color.length == v7) {
                    try {
                        FeedCellStyleConfig.color = new int[]{
                                Color.parseColor(FeedCellStyleConfig.mFeedCellConfigModel.color[0]),
                                Color.parseColor(FeedCellStyleConfig.mFeedCellConfigModel.color[1]),
                                Color.parseColor(FeedCellStyleConfig.mFeedCellConfigModel.color[2]),
                                Color.parseColor(FeedCellStyleConfig.mFeedCellConfigModel.color[3])};
                    } catch (Exception v0_2) {
                        Logger.d(FeedCellStyleConfig.TAG, v0_2.toString());
                    }
                }

                if (FeedCellStyleConfig.mFeedCellConfigModel != null && FeedCellStyleConfig.mFeedCellConfigModel.cell_background_color != null && FeedCellStyleConfig.mFeedCellConfigModel.cell_background_color.length == v7) {
                    try {
                        FeedCellStyleConfig.cell_background_color = new int[]{
                                Color.parseColor(FeedCellStyleConfig.mFeedCellConfigModel.cell_background_color[0]),
                                Color.parseColor(FeedCellStyleConfig.mFeedCellConfigModel.cell_background_color[1]),
                                Color.parseColor(FeedCellStyleConfig.mFeedCellConfigModel.cell_background_color[2]),
                                Color.parseColor(FeedCellStyleConfig.mFeedCellConfigModel.cell_background_color[3])};
                    } catch (Exception exception) {
                        Logger.d(FeedCellStyleConfig.TAG, exception.toString());
                    }
                }

            }
        }
    }

    public FeedCellStyleConfig() {

    }

    public static StateListDrawable getCellBackgroundColor(boolean isNightMode) {
        StateListDrawable stateListDrawable;
        int v2 = 16842919;
        if (FeedCellStyleConfig.cell_background_color == null || FeedCellStyleConfig.cell_background_color.length != 4) {
            stateListDrawable = null;
        } else {
            stateListDrawable = new StateListDrawable();
            if (isNightMode) {
                stateListDrawable.addState(new int[]{v2}, new ColorDrawable(FeedCellStyleConfig.cell_background_color[3]));
                stateListDrawable.addState(new int[0], new ColorDrawable(FeedCellStyleConfig.cell_background_color[1]));
            } else {
                stateListDrawable.addState(new int[]{v2}, new ColorDrawable(FeedCellStyleConfig.cell_background_color[2]));
                stateListDrawable.addState(new int[0], new ColorDrawable(FeedCellStyleConfig.cell_background_color[0]));
            }
        }

        return stateListDrawable;
    }

    public static void setCellBackgroundColor(View view) {
        if (view != null) {
            AppData.getInstance();
            StateListDrawable stateListDrawable = FeedCellStyleConfig.getCellBackgroundColor(AppData.isNightMode());
            if (stateListDrawable != null && Build.VERSION.SDK_INT < 21) {
                UIUtils.setBackgroundDrawable(view, stateListDrawable);
            }
        }
    }

    public static void setCellBackgroundColor(View view, int arg5) {
        if (view != null) {
            if (FeedCellStyleConfig.cell_background_color != null && FeedCellStyleConfig.cell_background_color.length == 4) {
                AppData.getInstance();
                boolean isNightMode = AppData.isNightMode();
                if (Build.VERSION.SDK_INT < 21) {
                } else if (FeedCellStyleConfig.cell_background_color == null) {
                } else if (FeedCellStyleConfig.cell_background_color.length == 4) {
                    int cellBackgroundColor = isNightMode ? FeedCellStyleConfig.cell_background_color[1] : FeedCellStyleConfig.cell_background_color[0];
                    FeedCellStyleConfig.setBackgroundColor(view, cellBackgroundColor);
                }
                return;
            }
            view.setBackgroundColor(arg5);
        }
    }

    public static void a(ImageView arg0) {
    }

    public static void setTextSize(TextView tv, int arg6) {
        if (tv != null) {
            int[] v3 = FeedCellStyleConfig.font_size;
            int v2 = AppData.getInstance().u() != null ? 2 : 0;
            if (v3 != null && v3.length > 0) {
                int v0 = AppData.getInstance().mFontSizePref;
                if (v0 >= v3.length || v0 < 0) {
                    v0 = 0;
                }

                if (v3[v0] <= 0) {
                } else {
                    tv.setTextSize(((float) (v3[v0] + v2)));
                    return;
                }
            }

            if (arg6 <= 0) {
                return;
            }

            tv.setTextSize(((float) (arg6 + v2)));
        }
    }

    public static void a(TextView tv, ColorStateList colorStateList) {
        ColorStateList v0_1;
        int[][] v2;
        int[] v1_1;
        int v8 = 3;
        int v7 = -16842910;
        int v6 = 2;
        if (tv != null) {
            AppData.getInstance();
            boolean isNightMode = AppData.isNightMode();
            int[] v0 = FeedCellStyleConfig.color;
            if (AppData.getInstance().u() != null) {
                v0 = new int[4];
                v0[0] = Color.parseColor("#000000");
                v0[1] = Color.parseColor("#707070");
                v0[v6] = Color.parseColor("#999999");
                v0[v8] = Color.parseColor("#7f707070");
            }

            if (v0 == null || v0.length != 4) {
                v0_1 = null;
            } else if (isNightMode) {
                v1_1 = new int[v6];
                v1_1[0] = v0[v8];
                v1_1[1] = v0[v6];
                v2 = new int[v6][];
                v2[0] = new int[]{v7};
                v2[1] = new int[0];
                v0_1 = new ColorStateList(v2, v1_1);
            } else {
                v1_1 = new int[v6];
                v1_1[0] = v0[1];
                v1_1[1] = v0[0];
                v2 = new int[v6][];
                v2[0] = new int[]{v7};
                v2[1] = new int[0];
                v0_1 = new ColorStateList(v2, v1_1);
            }

            if (v0_1 != null) {
                tv.setTextColor(v0_1);
                return;
            }

            if (colorStateList == null) {
                return;
            }

            tv.setTextColor(colorStateList);
        }
    }

    private static void setBackgroundColor(View view, int colorResId) {
        if (view != null) {
            int paddingLeft = view.getPaddingLeft();
            int paddingRight = view.getPaddingRight();
            int paddingTop = view.getPaddingTop();
            int paddingBottom = view.getPaddingBottom();
            view.setBackgroundColor(colorResId);
            view.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
        }
    }

    public static void adaptCellNightMode(View view) {
        if (view != null) {
            AppData.getInstance();
            boolean isNightMode = AppData.isNightMode();
            if (Build.VERSION.SDK_INT >= 21
                    && FeedCellStyleConfig.cell_background_color != null
                    && FeedCellStyleConfig.cell_background_color.length == 4) {
                int v0_1 = isNightMode ? FeedCellStyleConfig.cell_background_color[1] : FeedCellStyleConfig.cell_background_color[0];
                FeedCellStyleConfig.setBackgroundColor(view, v0_1);
            }
        }
    }
}

